const md5 = require('../../../utils/md5.js');
const http = require('../../../utils/http.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
        reply:[
            { img: '/images/k2.png', text: '电脑故障', url:'/pages/myinfo/customserver/computerFault/computerFault'},
            { img: '/images/guz.png', text: '座仓故障', url: '/pages/myinfo/customserver/cabinFault/cabinFault' },
            { img: '/images/k4.png', text: '网络故障', url: '/pages/myinfo/customserver/netFault/netFault' }
        ],
      msg: [{ name: '仓门故障', "state": 0 }, { name: '断网', "state": 0 }, { name: '机器故障', "state": 0 }, { name: '电脑故障', "state": 0 }, { name: '如何充值', "state": 0 }, { name: '认证', "state": 0 }, { name: '我的红包', "state": 0 }, { name: '我的积分', "state": 0 }],
      checkFail:[],
      feedBack:''  
       
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
    changeColor(e){  //保存选择问题的值
        console.log(e)
        let index = e.currentTarget.dataset.index;
        let msg = e.currentTarget.dataset.msg;
        if(this.data.msg[index].state==1){
            this.data.msg[index].state = 0;
            this.data.checkFail.splice(this.data.checkFail.indexOf(msg),1)
        } else if (this.data.msg[index].state == 0){
            this.data.msg[index].state=1;
            this.data.checkFail.push(msg)
        }
        console.log(this.data.checkFail)
        this.setData({
           msg:this.data.msg
        })
    },
    textMsg(e){ //留言反馈
        console.log(e.detail.value)
        this.setData({
            feedBack:e.detail.value
        })
    },
    tell(){
        wx.makePhoneCall({
            phoneNumber: '400008008',
        })
    },
    clickSubmit(){
        let _this = this
        let data={
            method:'Feedback.feedback',
            type:4,
            tags: _this.data.checkFail,
            describe: _this.data.feedBack,
            token:wx.getStorageSync('token')
        }
        let arr = http.sorts(data)
        //console.log(arr)
        data.sign = md5.hex_md5(arr)
        http._post(data,res=>{
            console.log(res)
            if(res.data.code==0){
                wx.showToast({
                    title: res.data.msg,
                    icon:'none',
                    duration:1000
                })
            }else{
                wx.showToast({
                    title: res.data.msg,
                    icon: 'none',
                    duration: 1500
                })
            }
        })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})